package com.zhangzhan.controller;

import com.zhangzhan.domain.commcon.ResponseResult;
import com.zhangzhan.domain.dto.PageUserDto;
import com.zhangzhan.domain.dto.SaveUserDto;
import com.zhangzhan.domain.dto.UpdateUserDto;
import com.zhangzhan.domain.dto.UserChangeStatusDto;
import com.zhangzhan.domain.vo.PageVO;
import com.zhangzhan.domain.vo.UpdateUserRoleVO;
import com.zhangzhan.service.UserService;
import org.apache.coyote.OutputBuffer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 张一恒
 * @version 1.0
 * @description:
 * @date 2022/12/8 8:42
 */
@RestController
@RequestMapping("/system/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/list")
    public ResponseResult<PageVO> userPage(Integer pageNum, Integer pageSize, PageUserDto pageUserDto){
        return userService.userPage(pageNum, pageSize, pageUserDto);
    }

    /**
     * @description 新增用户
     * @param dto
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/8 9:47
     */
    @PostMapping
    public ResponseResult saveUser(@RequestBody SaveUserDto dto){
        return userService.saveUser(dto);
    }


    /**
     * @description 批量删除
     * @param ids
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/8 10:19
     */
    @DeleteMapping("{id}")
    public ResponseResult deleteUserById(@PathVariable("id") Long[] ids){
        return userService.deleteByIds(ids);
    }

    /**
     * @description 根据id查询用户信息回显接口
     * @param id 
     * @return com.zhangzhan.domain.commcon.ResponseResult<com.zhangzhan.domain.vo.UpdateUserRoleVO>
     * @author 31115 
     * @date 2022/12/8 10:34
     */
    @GetMapping("{id}")
    public ResponseResult<UpdateUserRoleVO> selectById(@PathVariable("id") Long id) {
        return userService.selectById(id);
    }

    /**
     * @description 更新用户信息接口
     *
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/8 10:51
     */
    @PutMapping
    public ResponseResult updateUser(@RequestBody UpdateUserDto dto){
        return userService.updateUser(dto);
    }

    /**
     * @description 修改用户状态
     * @param
     * @return
     * @author 31115
     * @date 2022/12/8 11:14
     */
    @PutMapping("/changeStatus")
    public ResponseResult changeStatus(@RequestBody UserChangeStatusDto dto){
        return userService.changeStatus(dto);
    }
}
